package org.example.exception;

import org.example.constants.RspEnum;

/**
 * @author jingjing.zhang
 */
public class RspException extends Exception {
    private static final long serialVersionUID = 5676736954024398665L;
    private String code;

    private String msg;

    public RspException(String code, String msg) {
        super("[" + code + "]" + msg);
        this.code = code;
        this.msg = msg;
    }

    public RspException(String code, String msg, Throwable cause) {
        super("[" + code + "]" + msg, cause);
        this.code = code;
        this.msg = msg;
    }

    public RspException(RspEnum rspEnum, String... args) {
        super("[" + rspEnum.getCode() + "]" +  String.format(rspEnum.getMsg(), args));
        this.code = rspEnum.getCode();
        this.msg = String.format(rspEnum.getMsg(), args);
    }

    public RspException(RspEnum rspEnum) {
        super("[" + rspEnum.getCode() + "]" + rspEnum.getMsg());
        this.code = rspEnum.getCode();
        this.msg = rspEnum.getMsg();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
